﻿using System;
using System.Drawing;
using System.Windows;
using System.Windows.Media;

namespace YArchitech.LIB.YJKControls
{
	public class WinDPIManager
	{
		public static void GetWpfXYDpiScale(Visual fromThis, ref double xDPIScale, ref double yDPIScale)
		{
			PresentationSource presentationSource = PresentationSource.FromVisual(fromThis);
			if (presentationSource != null)
			{
				xDPIScale = presentationSource.CompositionTarget.TransformToDevice.M11;
				yDPIScale = presentationSource.CompositionTarget.TransformToDevice.M22;
			}
		}

		public static void GetWinFormXYDpi(ref double Xdpi, ref double Ydpi)
		{
			using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
			{
				Xdpi = (double)graphics.DpiX;
				Ydpi = (double)graphics.DpiY;
			}
			Xdpi /= 96.0;
			Ydpi /= 96.0;
		}

		private static bool StringToInt32(string strValue, ref int nValue)
		{
			bool result;
			try
			{
				nValue = Convert.ToInt32(strValue);
				result = true;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}
	}
}
